package www.wen.com.common.lib.util;

import java.text.DecimalFormat
import java.util.regex.Matcher
import java.util.regex.Pattern

/**x
 * @author WEN
 * @Description:
 * @date 2021/3/12 10:35
 */
class NumberFormatUtil {

    companion object{

        /**
         * 以四舍五入的方式保留2位小数
         */
        @JvmStatic
        fun roundingOffNumbers(number: Float, format: String = "#.00"):Float{
            val decimalFormat = DecimalFormat(format)
            return decimalFormat.format(number).toFloat()
        }

        /**
         * 判断是否数字
         */
        @JvmStatic
        fun isNumeric(str: String): Boolean {
            val pattern: Pattern = Pattern.compile("^[+]?(\\d+)\$")
            val isNum: Matcher = pattern.matcher(str)
            return isNum.matches()
        }

    }

}

